package leetcode_bin_tree_test;

import bin_tree.MyBinTree;
import bin_tree.TreeNode;

/**
 * 783. 二叉搜索树节点最小距离
 */
public class MinDiffInBST {
    int sub = 100001;
    TreeNode next;
    public int minDiffInBST(TreeNode root) {
        if (root.left != null) {
            minDiffInBST(root.left);
        }
        if (next != null) {
            sub = Math.min(sub, root.val - next.val);
        }
        next = root;
        if (root.right != null) {
            minDiffInBST(root.right);
        }
        return sub;
    }

}
